/**
 *  @author senhu chen
 */
app.factory('interInterviewService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function() {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/interview/findDrmsInterviews',
				method: 'POST',
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				reject('interInterviewService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('interAddService', ['$http', function($http){
	var baseUrl = '/DRMS/api';
	var interAddService = {
			interviews: function(inters) {
			    var promise = $http({
			    	url: baseUrl + '/interview/insertDrmsInterviews',
			    	method: 'POST',
			    	headers: {
			    		'Content-Type': 'application/json'
			    	},
			    	data: inters
			    }).then(function successCallback(response) {
			    	return response.data;
			    }, function errorCallback(response) {
			    	console.log(response);
			    });
			    return promise;
			},
	 };
	return interAddService;
}]);

app.factory('interUpdateService', ['$http', function($http){
	var baseUrl = '/DRMS/api';
	var interUpdateService = {
		interUpdate: function(inters) {
			console.log(inters);
		    var promise = $http({
		    	url: baseUrl + '/interview/updateDrmsInterviews',
		    	method: 'POST',
		    	headers: {
		    		'Content-Type': 'application/json'
		    	},
		    	data: inters
		    }).then(function successCallback(response) {
		    	return response.data;
		    }, function errorCallback(response) {
		    	console.log(response.data);
		    });
		    return promise;
		},
	 };
	return interUpdateService;
}]);

app.factory('interInfoService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function(id) {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/interview/findDrmsInterviewInfos',
				method: 'POST',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: 'id='+id
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				reject('interInfoService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('interInfoAddService', ['$http', function($http){
	var baseUrl = '/DRMS/api';
	var interInfoAddService = {
			interviews: function(interInfos) {
			    var promise = $http({
			    	url: baseUrl + '/interview/insertDrmsInterviewInfos',
			    	method: 'POST',
			    	headers: {
			    		'Content-Type': 'application/json'
			    	},
			    	data: interInfos
			    }).then(function successCallback(response) {
			    	return response.data;
			    }, function errorCallback(response) {
			    	console.log(response);
			    });
			    return promise;
			},
	 };
	return interInfoAddService;
}]);

app.factory('statusAddService', ['$http', function($http){
	var baseUrl = '/DRMS/api';
	var statusAddService = {
		interviews: function(inters){
			var promise = $http({
				url: baseUrl + '/interview/updateInterviewStatus',
				method: 'POST',
				headers: {
					'Content-Type': 'application/json'
				},
				data: inters
			}).then(function successCallback(response){
				return response.data;
			}, function errorCallback(response){
				
			});
			return promise;
		},
	};
	return statusAddService;
}]);

app.factory('findDmdShowIdService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function() {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/demandrequest/findDmdShowId',
				method: 'POST',
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				reject('findDmdShowIdService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('findCandShowIDService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function() {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/drmscandidate/findCandShowId',
				method: 'POST',
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				reject('findCandShowIDService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('findCandNameService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return function(candShowId) {
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/drmscandidate/findCandName',
				method: 'POST',
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
				data: 'candShowId=' + candShowId
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				console.log(response);
				reject('findCandNameService - reject');
			});
		});
		return promise;
	}
}]);

app.factory('sendOnboardingService', ['$http','$q', function($http,$q){
	var baseUrl = '/DRMS/api';
	return function(inter) {
		console.log(inter);
		var promise = $q(function(resolve, reject) {
			$http({
				url: baseUrl + '/interview/insertOnboarding',
				method: 'POST',
				headers: {
					'Content-Type': 'application/json'
				},
				data: inter
			}).then(function(response) {
				resolve(response.data);
			}, function(response) {
				console.log(response);
				reject('sendOnboardingService - reject');
			});
		});
		return promise;
	}
}]);